$(function(){
    $("#login").on("click",function(){
        var username = $("[name='username']").val();
        var mobile = $("[name='mobile']").val();
        var password = $("[name='password']").val();
        var againPass = $("[name='againPass']").val();
        var vCode = $("[name='vCode']").val();

        if(!username){
            mui.toast("请输入用户名");
            return;
        }
        if(mobile.length < 11){
            mui.toast("请输入手机号");
            return;
        }
        if(password != againPass){
            mui.toast("密码不一致，请重新输入");
            return;
        }

        $.ajax({
            type: "post",
            url: "/user/register",
            data: {
                username:username,
                mobile:mobile,
                password:password,
                vCode: vCode
            },
            success: function (response) {
                if(response.success == true){
                    mui.toast("注册成功");
                    setTimeout(function(){
                        location.href = "user.html";
                    },2000); 
                }else {
                    mui.toast("注册失败,请重新注册");
                }  
                
            }
        });
    });

    $(".getCode").on("click",function(){
        if($(this).hasClass("doing")){
            return;
        }
        var str = $(this).addClass("doing");
        console.log(str);
        $(this).text("正在请求...");
        var This = this;
        setTimeout(function(){
            $(This).removeClass("doing");
            $(This).text("获取认证码");
        },3000);

        $.ajax({
            type: "get",
            url: "/user/vCode",
            success: function (response) {
                console.log(response);
            }
        });
    });

});